package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.entity.Resource;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.MenuVo;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeItemVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: ResourcesController
 * @description:
 * @author: InnovatorX
 * @date: 2024/6/1 21:44
 * @Version: 1.0
 */
@Slf4j
@RestController
@Api(tags = "资源列表")
@RequestMapping("/resource")
public class ResourcesController {
    @Autowired
    private ResourceService resourceService;

    /**
     * 资源添加
     * @return
     */
    @PutMapping
    @ApiOperation(value = "资源添加", notes = "资源添加")
    public ResponseResult addResources(@RequestBody ResourceDto resourceDto) {
        Resource bean = BeanUtil.toBean(resourceDto, Resource.class);

        resourceService.addResources(bean);
        return ResponseResult.success();
    }

    /**
     * 资源修改
     * @return
     */
    /*@PatchMapping
    @ApiOperation(value = "资源修改", notes = "资源修改")
    public ResponseResult updateResources() {
        return ResponseResult.success();
    }*/

    /**
     * 0启用-1禁用
     * @return
     */
    /*@PostMapping
    @ApiOperation(value = "0启用-1禁用", notes = "0启用-1禁用")
    public ResponseResult isEnable() {
        return ResponseResult.success();
    }*/

    /**
     * 查询资源列表
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "资源列表", notes = "资源列表")
    public ResponseResult<List<ResourceVo>> listResources(@RequestBody ResourceDto resourceDto) {
        List<ResourceVo> resourceVos = resourceService.listResources(resourceDto);
        return ResponseResult.success(resourceVos);
    }

    /**
     * 后台管理登录后, 获取当前用户的菜单
     * @return
     */
    @GetMapping("/menus")
    @ApiOperation(value = "左侧菜单", notes = "左侧菜单")
    public ResponseResult<List<MenuVo>> menus() {
        List<MenuVo> menuVos = resourceService.menus();
        return ResponseResult.success(menuVos);
    }

    /**
     * 我的按钮列表
     * @return
     */
    /*@GetMapping("/myButten")
    @ApiOperation(value = "我的按钮列表", notes = "我的按钮列表")
    public ResponseResult myButten() {
        return ResponseResult.success();
    }*/

    /**
     * 资源树形
     * @return
     */
    @PostMapping("/tree")
    @ApiOperation(value = "资源树形", notes = "资源树形")
    public ResponseResult<TreeVo> tree(@RequestBody TreeItemVo treeItemVo) {
       TreeVo treeVo = resourceService.findResourceTree(treeItemVo);
        return ResponseResult.success(treeVo);
    }

    /**
     * 删除菜单
     * @param menuId
     * @return
     */
    /*@DeleteMapping("/{menuId}")
    @ApiOperation(value = "删除菜单", notes = "删除菜单")
    public ResponseResult remove(@PathVariable String menuId) {
        return ResponseResult.success();
    }*/
}
